#define _CRT_SECURE_NO_WARNINGS 1

int gcd(int a, int b)
{
    while (a % b != 0)
    {
        int c = a % b;
        a = b;
        b = c;
    }
    return b;
}

int front(int a)
{
    while (a)
    {
        if (a / 10 == 0)
        {
            break;
        }
        a /= 10;
    }
    return a;
}

int back(int a)
{
    return a % 10;
}

int countBeautifulPairs(int* nums, int numsSize) {
    int i = 0;
    int j = 0;
    int count = 0;
    for (i = 0; i < numsSize - 1; i++)
    {
        for (j = i + 1; j < numsSize; j++)
        {
            if (gcd(front(nums[i]), back(nums[j])) == 1)
                count++;
        }
    }
    return count;
}